
// 定期执行的
export function interval(fn: ((...args: any[]) => void), time: number, fistNoWait?:boolean) {
  let isCalled = false;
  let timeoutId = 0;

   function run() {
     if (fistNoWait && !isCalled) {
       fn()
       isCalled = true;
     } else {
       timeoutId = window.setTimeout(() => {
         fn();

         if (!isCalled) {
           isCalled = true;
         }

         run();
       }, time);
     }
   }

   run.abort = () => {
     timeoutId && clearTimeout(timeoutId);
   }

   return run;
}